package com.example.module_motorcircle.report.viewmodel

import com.example.lib_common.base.BaseViewModel
import com.example.lib_common.state.UIState
import com.example.lib_net.model.api.ReportTypeModel
import com.example.module_motorcircle.report.repository.ReportRepository
import dagger.hilt.android.lifecycle.HiltViewModel
import kotlinx.coroutines.flow.MutableStateFlow
import kotlinx.coroutines.flow.asStateFlow
import javax.inject.Inject

/**
 * @author yaotianxue
 * @description
 * @date 2025/2/14
 */
@HiltViewModel
class ReportViewModel @Inject constructor(private val repository: ReportRepository) : BaseViewModel() {

    /**
     * 获得举报类型
     */
    private val reportTypeListState  = MutableStateFlow<UIState>(UIState.Default)
    val reportTypeListState_ = reportTypeListState.asStateFlow()
    lateinit var mReportTypeList:List<ReportTypeModel>
    fun reportTypeList(){
        execute(
            action = repository.reportTypeList(),
            onStart = {
                reportTypeListState.value = UIState.Loading
            },
            onError = {
                reportTypeListState.value = UIState.Error(it)
            },
            onFinished = {
                if(it.data.isNullOrEmpty()){
                    reportTypeListState.value = UIState.Empty
                }else{
                    mReportTypeList = it.data
                    reportTypeListState.value = UIState.Success
                }

            }
        )
    }
    /**
     * 举报帖子
     */
    private val reportState  = MutableStateFlow<UIState>(UIState.Default)
    val reportState_ = reportState.asStateFlow()
    fun reportPost(id:String,tipOffType:String){
        execute(
            action = repository.reportPost(id,tipOffType),
            onStart = {
                reportState.value = UIState.Loading
            },
            onError = {
                reportState.value = UIState.Error(it)
            },
            onFinished = {
                reportState.value = UIState.Success
            }
        )
    }
}